#include <iostream>
#include <unistd.h>
#include <pthread.h>
#include <cstdio>
#include <string>

using namespace std;

void* threadRun(void* args)
{
    const string name = (char*)args;
    while (true)
    {
        cout << "新线程: "<< name << ", pid: " << getpid() << endl;
        sleep(1);
    }
}

int main()
{
    pthread_t tid[5];
    char name[64];
    for (int i = 0; i < 5; i++)
    {
        snprintf(name, sizeof(name), "thread-%d", i);
        pthread_create(tid + i, nullptr, threadRun, (void*)name);
        sleep(1);
    }

    while (true) 
    {
        cout << "主线程, pid: " << getpid() << endl;
        sleep(3);
    }

    return 0;
}